﻿using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Inspinia_MVC5.Code
{
    //跨域过滤器，允许跨域访问
    public class AllowCorsAttribute : ActionFilterAttribute
    {
        private string[] _domains;

        public AllowCorsAttribute(params string[] domains)
        {
            _domains = domains;
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var context = filterContext.RequestContext.HttpContext;
            if (context.Request.UrlReferrer != null)
            {
                var origin = context.Request.UrlReferrer.Scheme + "://" + context.Request.UrlReferrer.Host;
                if (context.Request.UrlReferrer.Port != 80)
                {
                    origin += ":" + context.Request.UrlReferrer.Port;
                }
                context.Response.AddHeader("Access-Control-Allow-Origin", origin);
            }
            else
            {
                context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            }
            context.Response.AddHeader("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST, PUT");
            // context.Response.AddHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
            context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
            base.OnActionExecuting(filterContext);
        }
    }
    //继承DLL中的类以便在程序中使用，功能是生成password的HASH值
    public class PassswordHash : PasswordHasher
    {
        public PassswordHash()
        {

        }
    }
}